
local figure "_regions_voting"
shp2dta using ../2_Data/shapefile/Reg01012018_g.shp, data(../2_Data/shapefile/it_datareg.dta) coor(../2_Data/shapefile/it_coorreg.dta) genid(_ID) replace


use "../2_Data/shapefile/it_datareg.dta", clear
rename (DEN_REG COD_REG) (region region_code)
replace region = strupper(region)
preserve

use "../2_Data/shapefile/it_coorreg.dta", clear
merge m:1 _ID using "../2_Data/shapefile/it_datareg.dta", assert(match) nogen
gen election = (COD_REG==9 | COD_REG==16 | COD_REG == 7 | COD_REG==5 | COD_REG==2 | COD_REG==14 | COD_REG==11)

save "../2_Data/shapefile/it_coorreg_selected.dta", replace

use "../2_Data/temp/data_covid_region.dta", clear
keep region

replace region = "TRENTINO-ALTO ADIGE" if strpos(region,"P.A.")!=0
duplicates drop 

tempfile skel
save `skel', replace

restore

merge m:1 region using `skel'
assert _merge==3 if region!=""
drop if region==""
drop _merge


tempfile shape
save `shape', replace

use "../2_Data/temp/Data_selected.dta", clear

collapse (firstnm) election, by(region)

replace region = "TRENTINO-ALTO ADIGE" if strpos(region,"P.A.")!=0
duplicates drop 
merge 1:1 region using `shape', assert(match) nogen

spmap election using "../2_Data/shapefile/it_coorreg.dta", id(_ID) ocolor(black ..) osize(*0.5 ..) clmethod(unique) fcolor($color_noelection $color_election) /*
*/ legend(symy(*1.5) symx(*1.5) size(*1.5)) polygon(data("../2_Data/shapefile/it_coorreg_selected.dta") fcolor(white) /// 
   ocolor(black black) osize(*0.015 *0.015)) polyfirst  legend(label(3 "No Campaign") label(4 "Campaign") order(3 4) pos(2)) title("(a) Geographical distribution of regional campaigns", size(small))

 

use "../2_Data/temp/rai_data.dta", clear

replace region=strupper(region)
replace region="EMILIA-ROMAGNA" if strpos(region,"EMILIA")!=0
replace region="TRENTINO-ALTO ADIGE" if strpos(region,"TRENTINO")!=0

preserve

use "../2_Data/temp/data_selected_region.dta", clear

replace region="TRENTINO-ALTO ADIGE" if strpos(region,"P.A.")!=0

collapse (firstnm) post_election time_fe_region x_region y_region election week region_code, by(region date)


tempfile regions
save `regions', replace

restore

merge 1:1 region date using `regions',nogen

replace number = 0 if number==.

replace week = 42 if date==d(16oct2020) | date==d(17oct2020) | date==d(18oct2020)

replace election = 1 if election==. & (region == "VENETO" | region == "LIGURIA" | region == "VALLE D'AOSTA" | region == "MARCHE" | region == "CAMPANIA" | region == "TOSCANA" | region == "PUGLIA")
replace election = 0 if election==. & region != "VENETO" & region != "LIGURIA" & region != "VALLE D'AOSTA" & region != "MARCHE" & region != "CAMPANIA" & region != "TOSCANA" & region != "PUGLIA"

local var number

gen  mean_`var'=0
gen ciu_`var' = 0
gen cil_`var' = 0
forvalues week = 27 / 42 {
cap reg `var' if election==1 & week==`week', r
cap replace mean_`var' = _b[_cons] if election==1 & week==`week'
cap drop se
cap gen se = _se[_cons]

cap replace ciu_`var' = mean_`var'+1.96*se if election==1 & week==`week'
cap replace cil_`var' = mean_`var'-1.96*se if election==1 & week==`week'

cap reg `var' if election==0 & week==`week', r
cap replace mean_`var' = _b[_cons] if election==0 & week==`week'
cap drop se
cap gen se = _se[_cons]

cap replace ciu_`var' = mean_`var'+1.96*se if election==0 & week==`week'
cap replace cil_`var' = mean_`var'-1.96*se if election==0 & week==`week'

}

replace week = week-0.2 if election==0
replace week = week+0.2 if election==1

local figure "_bar_rai"

twoway (bar mean_number week if election==1, barwidth(0.5) color($color_election)) (bar mean_number week if election==0, barwidth(0.5) color($color_noelection)) (rcap ciu_number cil_number week, color(black)), ///
xline(34, lcolor(gs10) lpattern("--")) xline(38, lcolor(gs10) lpattern("--")) ///
xlabel(27 "Jul. 5" 28 "Jul. 12" 29 "Jul. 19" 30 "Jul. 26" 31 "Aug. 2" 32 "Aug. 9" 33 "Aug. 16" 34 "Aug. 23" 35 "Aug. 30" 36 "Sep. 6" 37 "Sep. 13" 38 "Sep. 20" 39 "Sep. 27" 40 "Oct. 4" 41 "Oct. 11" 42 "Oct. 18", labsize(large) angle(45)) ///
ylab(,labsize(vlarge) angle(0) labgap(large)) title("(b) No. mentions of political leaders" "on regional TV news", size(vlarge) color(black)) xtitle("") ///
scheme(s1mono) legend(off) xsize(7) ysize(5)


import excel using "../2_Data/raw/salvini/salvini.xlsx", firstrow clear
gen number_salvini = 1
tostring day month, replace
gen ddate = day+"/"+month+"/"+"2020"
gen date = date(ddate,"DMY",2000)

collapse (sum) number_salvini, by(date region)

replace region=strupper(region)
replace region="EMILIA-ROMAGNA" if strpos(region,"EMILIA")!=0
replace region="TRENTINO-ALTO ADIGE" if strpos(region,"TRENTINO")!=0

preserve

use "../2_Data/temp/data_selected_region.dta", clear

replace region="TRENTINO-ALTO ADIGE" if strpos(region,"P.A.")!=0

collapse (firstnm) post_election time_fe_region x_region y_region election week region_code, by(region date)


tempfile regions
save `regions', replace

restore

merge 1:1 region date using `regions',nogen

replace number_salvini = 0 if number_salvini==.



replace week = 42 if date==d(16oct2020) | date==d(17oct2020) | date==d(18oct2020)

replace election = 1 if election==. & (region == "VENETO" | region == "LIGURIA" | region == "VALLE D'AOSTA" | region == "MARCHE" | region == "CAMPANIA" | region == "TOSCANA" | region == "PUGLIA")
replace election = 0 if election==. & region != "VENETO" & region != "LIGURIA" & region != "VALLE D'AOSTA" & region != "MARCHE" & region != "CAMPANIA" & region != "TOSCANA" & region != "PUGLIA"

local var number_salvini

gen  mean_`var'=0
gen ciu_`var' = 0
gen cil_`var' = 0
forvalues week = 27 / 42 {
cap reg `var' if election==1 & week==`week', r
cap replace mean_`var' = _b[_cons] if election==1 & week==`week'
cap drop se
cap gen se = _se[_cons]

cap replace ciu_`var' = mean_`var'+1.96*se if election==1 & week==`week'
cap replace cil_`var' = mean_`var'-1.96*se if election==1 & week==`week'

cap reg `var' if election==0 & week==`week', r
cap replace mean_`var' = _b[_cons] if election==0 & week==`week'
cap drop se
cap gen se = _se[_cons]

cap replace ciu_`var' = mean_`var'+1.96*se if election==0 & week==`week'
cap replace cil_`var' = mean_`var'-1.96*se if election==0 & week==`week'

}

replace week = week-0.2 if election==0
replace week = week+0.2 if election==1

local figure "_bar_salvini"

twoway (bar mean_number_salvini week if election==1, barwidth(0.5) color($color_election)) (bar mean_number_salvini week if election==0, barwidth(0.5) color($color_noelection)) (rcap ciu_number_salvini cil_number_salvini week, color(black)), ///
xline(34, lcolor(gs10) lpattern("--")) xline(38, lcolor(gs10) lpattern("--")) ///
xlabel(27 "Jul. 5" 28 "Jul. 12" 29 "Jul. 19" 30 "Jul. 26" 31 "Aug. 2" 32 "Aug. 9" 33 "Aug. 16" 34 "Aug. 23" 35 "Aug. 30" 36 "Sep. 6" 37 "Sep. 13" 38 "Sep. 20" 39 "Sep. 27" 40 "Oct. 4" 41 "Oct. 11" 42 "Oct. 18", labsize(large) angle(45)) ///
ylab(0 "0" .5 "0.5" 1 "1" 1.5 "1.5",labsize(vlarge) angle(0)) title("(c) No. public events with" " Senator Matteo Salvini", size(vlarge) color(black)) ///
scheme(s1mono) legend(off) xsize(7) ysize(5) xtitle("") 

  
use "../2_Data/temp/data_selected.dta", clear


foreach var of varlist turnout* {
egen `var'_region=wtmean(`var'), by(region) weight(population)

}

collapse (firstnm) turnout *_region election, by(region)

foreach var of varlist turnout* {
replace `var'=`var'*100 
reg `var' if election==1, r
gen mean_`var' = _b[_cons] if election==1
cap drop se
gen se = _se[_cons]

gen ciu_`var' = mean_`var'+1.96*se if election==1
gen cil_`var' = mean_`var'-1.96*se if election==1

reg `var' if election==0, r
replace mean_`var' = _b[_cons] if election==0
cap drop se
gen se = _se[_cons]

replace ciu_`var' = mean_`var'+1.96*se if election==0
replace cil_`var' = mean_`var'-1.96*se if election==0

}

local figure "_turnout_bar"

gen help1 = 1
gen help2 = 0

gen help3 = 4
gen help4 = 3

gen help5 = 7
gen help6 = 6

gen help7 = 10
gen help8 = 9

twoway (bar mean_turnout_sunday12_region help1 if election==1, barwidth(0.9) color($color_election)) (rcap ciu_turnout_sunday12_region cil_turnout_sunday12_region help1 if election==1, color(black)) /// 
(bar mean_turnout_sunday12_region help2 if election==0, barwidth(0.9) color($color_noelection)) (rcap ciu_turnout_sunday12_region cil_turnout_sunday12_region help2 if election==0, color(black)) ///
(bar mean_turnout_sunday19_region help3 if election==1, barwidth(0.9) color($color_election)) (rcap ciu_turnout_sunday19_region cil_turnout_sunday19_region help3 if election==1, color(black)) /// 
(bar mean_turnout_sunday19_region help4 if election==0, barwidth(0.9) color($color_noelection)) (rcap ciu_turnout_sunday19_region cil_turnout_sunday19_region help4 if election==0, color(black)) ///
(bar mean_turnout_sunday23_region help5 if election==1, barwidth(0.9) color($color_election)) (rcap ciu_turnout_sunday23_region cil_turnout_sunday23_region help5 if election==1, color(black)) /// 
(bar mean_turnout_sunday23_region help6 if election==0, barwidth(0.9) color($color_noelection)) (rcap ciu_turnout_sunday23_region cil_turnout_sunday23_region help6 if election==0, color(black)) ///
(bar mean_turnout_final_region help7 if election==1, barwidth(0.9) color($color_election)) (rcap ciu_turnout_final_region cil_turnout_final_region help7 if election==1, color(black)) ///
(bar mean_turnout_final_region help8 if election==0, barwidth(0.9) color($color_noelection)) (rcap ciu_turnout_final_region cil_turnout_final_region help8 if election==0, color(black)), ///
xlab(0.5 "12PM" 3.5 "7PM" 6.5 "11PM" 9.5 "Overall", labsize(large) angle(45)) ylab(0(25)75,labsize(vlarge) angle(0)) title("(d) Voter turnout (%)" "at different times", size(vlarge) color(black)) scheme(s1mono) legend(off) xsize(7) ysize(5) xtitle("") 

   